package com.wiley.searchPO;

import io.appium.java_client.android.AndroidDriver;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;

import com.wiley.publicMethod.BasePage;
import com.wiley.publicMethod.LoggerControler;

import java.io.IOException;
import java.net.MalformedURLException;

public class CommunityPage extends BasePage {

	/**
	 * 页面元素
	 */

	//广场
	public static final By community_item_loc = By.id(BaseId + "community_item");
		
	//搜索商品
	public static final By search_topic_and_person_loc = By.id(BaseId + "search_topic_and_person");

	//点击搜索框弹出的输入框
	public static final By topic_input_loc = By.id(BaseId + "search_src_text");
	
	//搜索列表封面图片
	public static final By topic_cover_loc = By.id(BaseId + "cover");
	
	//当前页面的topic名
	public static final By topic_title_loc = By.id(BaseId+"title");

	/**
	 * 操作方法
	 */
	//点击广场
	public void clickCommunityItem(){
		this.clickEle(community_item_loc);
	}
	
	//点击搜索框，进入搜索页面
	public void clickTopicAndPersonSearchBox(){
		this.clickEle(search_topic_and_person_loc);
	}

	//定位输入框，输入话题名称
	public void inputTopic(String recipe){
		this.sendKeys(topic_input_loc,recipe);
	}
	
	//点击首张封面图片
	public void clickTopicCover(int i){
		this.clickEles(topic_cover_loc, i);
	}

	//topic名
	public String getTopicName(){
		WebElement ele = this.findEle(topic_title_loc);
		return ele.getText();
	}
	/**
	 * 业务封装
	 * @throws MalformedURLException 
	 */
	public void communitySearch(String topic,Class name) throws MalformedURLException {
		LoggerControler log = this.MyLogger(name);
		AndroidDriver driver = super.SetDriver();
		this.clickCommunityItem();
		this.clickTopicAndPersonSearchBox();
		this.inputTopic(topic);
		log.info("本次搜索的话题是："+topic);
		driver.sendKeyEvent(66);
		this.clickTopicCover(2);
		log.info("该话题名为："+this.getTopicName());
		super.captureScreen("Search_topic_"+topic);
		Assert.assertTrue(getTopicName().contains(topic));
		log.info("该case测试通过");
	}
}
